unit uJfglService;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
  DB, ADODB,ActiveX;

type
  TJfglService = class(TService)
    procedure ServiceStart(Sender: TService; var Started: Boolean);
    procedure ServiceStop(Sender: TService; var Stopped: Boolean);
    procedure ServicePause(Sender: TService; var Paused: Boolean);
    procedure ServiceShutdown(Sender: TService);
    procedure ServiceExecute(Sender: TService);
    procedure ServiceContinue(Sender: TService; var Continued: Boolean);
  private
    { Private declarations }
  public
    function GetServiceController: TServiceController; override;
    { Public declarations }
  end;

var
  JfglService: TJfglService;

implementation
uses uMain;
{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  JfglService.Controller(CtrlCode);
end;

function TJfglService.GetServiceController: TServiceController;
begin
  Result := ServiceController;
end;

procedure TJfglService.ServiceContinue(Sender: TService;
  var Continued: Boolean);
begin
  {
  while not Terminated do
  begin
     Sleep(10);
     ServiceThread.ProcessRequests(False);
  end;
  }
  Continued := true;
end;

procedure TJfglService.ServiceExecute(Sender: TService);
begin
  while not Terminated do
  begin
    Sleep(10);
    ServiceThread.ProcessRequests(false);
  end;
end;

procedure TJfglService.ServicePause(Sender: TService; var Paused: Boolean);
begin
  Paused := true;
end;

procedure TJfglService.ServiceShutdown(Sender: TService);
begin
  gbCanClose := true;
  MainForm.Free;
  Status := csStopped;
end;

procedure TJfglService.ServiceStart(Sender: TService; var Started: Boolean);
begin
  CoInitialize(nil);
  Started := true;
  SvcMgr.Application.CreateForm(TMainForm, MainForm);
  gbCanClose := false;
  MainForm.Hide;
end;

procedure TJfglService.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
  Stopped := true;
  gbCanClose := true;
  MainForm.Free;
  CoUnInitialize;
end;

end.
